<extend name='Index/index' />

<block name="main">
                <div class="bg-light lter b-b wrapper-md">
                    <h1 class="m-n font-thin h3">商品管理</h1>
                </div>
                <h4 style="margin-left:30px;"><a href="<{:U('Admin/Goods/add')}>" class="btn btn-info">添加商品</a></h4>
                <div class="wrapper-md">
                    <div class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-striped b-t b-light">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>商品名</th>
                                        <th>价格</th>
                                        <th>等级</th>
                                        <th>类型</th>
                                        <th>上架</th>
                                        <th style="text-align:center;">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <volist name="goodslist" id="vo">
                                        <tr>
                                            <td class="myId"><{$vo.g_id}></td>
                                            <td><{$vo.g_name}></td>
                                            <td><{$vo.price}></td>
                                            <td>
                                                <switch name="vo.g_rank">
                                                    <case value="0">普通</case>
                                                    <case value="1">稀有</case>
                                                    <case value="2">至宝</case>
                                                    <case value="3">神话</case>
                                                    <case value="4">传说</case>
                                                </switch>
                                            </td>
                                            <td><{$vo.g_type}></td>
                                            <td>
                                                <if condition="$vo.up eq 0"><a class="goodsUp">下架</a>
                                                <else /><a class="goodsUp">上架</a>
                                                </if>
                                            </td>
                                            <td>
                                                <a href="<{:U('Admin/Goods/edit?gid='.$vo['g_id'])}>" class="btn btn-info">编辑</a>
                                                <button class="btn btn-success myImgedit">图片管理</button>
                                                <button class="btn btn-danger">删除</button>
                                            </td> 
                                        </tr>
                                    </volist>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <p></p>
                    <p></p>
                </div>

                <script>
                    $('.myImgedit').click(function(){
                        var gid = $(this).parent().prevAll('.myId').html();
                        var str = "<{:U('Admin/Goodsimg/index?gid=province_id')}>";
                        var url =  str.replace("province_id",gid);
                        location = url;
                    });

                    $('.btn-danger').click(function(){
                        $(this).parents('tr').remove();
                        var gid = $(this).parent().prevAll('.myId').html();
                        $.ajax({
                            type: 'post',
                            url: "<{:U('Admin/Goods/delete')}>",
                            data: "gid="+gid
                        });
                    });

                    $('.goodsUp').click(function (){
                        var str = $(this).html();
                        var up = 0;
                        var gid = $(this).parent().prevAll('.myId').html();
                        if(str == '上架'){
                            $(this).html('下架');
                            up = 0;
                        }else{
                            $(this).html('上架');
                            up = 1;
                        }
                        $.ajax({
                            type: "post",
                            url: "<{:U('Admin/Goods/editUp')}>",
                            data: "gid="+gid+"&up="+up
                        });
                    });
                </script>
</block>